<?php

namespace common\Factory\Rabbitmq;

use common\Factory\ServerInterface;
use common\Factory\Factory;

class RabbitmqServer implements ServerInterface {
    
    private $_config;
    private $_host = 'localhost';
    private $_port = '5672';
    private $_login = 'guest';
    private $_password = 'guest';
    private $_vhost = '/';
    
    function __construct() {
        $config = \core\init\init::getConfig();
        if(isset($config['rabbitmq'])) {
            $this->_host = $config['rabbitmq']['host'];
            $this->_port = $config['rabbitmq']['port'];
            $this->_login = $config['rabbitmq']['login'];
            $this->_password = $config['rabbitmq']['password'];
            $this->_vhost = $config['rabbitmq']['vhost'];
        }
    }
    
    public function getObj() {
        $connArgs = array(
            'host' => $this->_host,
            'port' => $this->_port,
            'login' => $this->_login,
            'password' => $this->_password,
            'vhost'=> $this->_vhost
        );

        $rabbitmq = new \AMQPConnection($connArgs);
        
        return $rabbitmq;
    }
}